#include "pe_ccmenuitemfont.h"
#include "CCMenuItem.h"
#include "CCQTSceneDirector.h"

PE_CCMenuItemFont::PE_CCMenuItemFont(QtVariantPropertyManager *variantManager):PE_CCRGBAProtocol(variantManager)
{
    
}

QtProperty *PE_CCMenuItemFont::initUI()
{
    addProperty(QVariant::String , "Text");
	addProperty(QVariant::String , "FontName");
	addProperty(QVariant::Int , "FontSize");

	return PE_CCRGBAProtocol::initUI();
}



void PE_CCMenuItemFont::refresh()
{
	CCMenuItemFont * cnode = (CCMenuItemFont*)CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
	if (cnode == NULL) return;
	Property("Text")->setValue(cnode->getString());
    Property("FontName")->setValue(cnode->fontName());
	Property("FontSize")->setValue(cnode->fontSize());
	PE_CCRGBAProtocol::refresh();
}

void PE_CCMenuItemFont::valueChanged(QtProperty *property, QVariant variant)
{
    	CCMenuItemFont * cnode = (CCMenuItemFont*)CCQTSceneDirector::sharedSceneDirector()->CurrentCNode();
		if (property == Property("Text"))
		{
			cnode->setString(variant.value<QString>().toLocal8Bit());
		}
		else if (property == Property("FontName"))
		{
			ccColor3B color = cnode->getColor();
			int alpha = cnode->getOpacity();
			cnode->setFontName(variant.value<QString>().toLocal8Bit());
			cnode->setFontNameObj(variant.value<QString>().toLocal8Bit());
			cnode->setColor(color);
			cnode->setOpacity(alpha);
		}
		else if (property == Property("FontSize"))
		{
			ccColor3B color = cnode->getColor();
			int alpha = cnode->getOpacity();
			cnode->setFontSize(variant.value<int>());
			cnode->setFontSizeObj(variant.value<int>());
			cnode->setColor(color);
			cnode->setOpacity(alpha);
		}
		PE_CCRGBAProtocol::valueChanged(property ,variant);
}
